<?php
$v_staff_id = $_SESSION['staff_id'];
//Lay du lieu tu database
$v_query_data = false;
if(isset($_REQUEST['hdn_query_data'])){
	$v_query_data = true;
}
if ($v_record_id>0){
	$v_code_record = $arr_single_record['C_CODE'];
	$v_license_xml_data = $arr_single_record['C_POST_LICENSE_XML_DATA'];
	if ($v_query_data){
		$v_xml_str = $arr_single_record['C_RECEIVED_RECORD_XML_DATA'];		
	}else{
		$v_xml_str = $v_license_xml_data;	
	}
}else{
	$v_code_record = "123456";
	$v_license_xml_data = '<?xml version="1.0" encoding="UTF-8"?><root><data_list></data_list></root>';

}
$v_current_status = ($arr_single_record['C_CURRENT_STATUS']);
$v_detail_status = intval($arr_single_record['C_DETAIL_STATUS']);
if ($v_detail_status == 61){
	$v_detail_status_check = "checked";
}else{
	 $v_detail_status_check = "";
}
// xac dinh label hien thi: trinh ky, duoc giai quyet, khong duoc giai quyet
$arr_result_label = onegate_get_label_of_result_type($_SESSION['recordtype'],$v_recordtype_filter);

$v_staff_id = _get_item_attr_by_id ($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'id');
//Kiem tra NSD hien thoi dong vai tro la thu ly chinh doi voi ho so hien thoi va trang thai cua ho so la "CAP_PHEP" va C_DETAIL_STATUS <>20
if ( (onegate_is_main_handler_for_record($v_staff_id,$v_record_id)) && $v_detail_status <> 20){
	$v_is_main_handler_for_record_and_status = 1;
}else{
	$v_is_main_handler_for_record_and_status = 0;
}
//Kiem tra NSD hien thoi dong vai tro la thu ly chinh doi voi ho so hien thoi va trang thai cua ho so la "DANG_THU_LY" va C_DETAIL_STATUS <>20
if ( (onegate_is_main_handler_for_record($v_staff_id,$v_record_id))&& $v_current_status == "DANG_THU_LY" && $v_detail_status <> 20){
	$v_is_main_handler_for_record = 1;
}else{
	$v_is_main_handler_for_record = 0;
}
//echo htmlspecialchars($v_xml_str);
$v_process_date = 0;
for ($i=0; $i < sizeof($arr_all_recordtype);$i++){
	if ($arr_all_recordtype[$i]['0']==$v_recordtype_filter){
		$v_process_date = $arr_all_recordtype[$i]['4'];
		break;
	}
}

if (($v_recordtype_filter == 'other') || ($v_is_main_handler_for_record_and_status ==0)) {
	$v_display = "none";
}else{
	$v_display = "block";
}
//cac file chua cau truc cua bang
$v_table_struct_xml_file = "../../xml/".$v_recordtype_filter."/cau_truc_bang_noi_dung_sau_giay_phep.xml";
$v_formfield_xml_file = "../../xml/".$v_recordtype_filter."/cac_dong_cua_noi_dung_sau_giay_phep.xml";
//echo $v_formfield_xml_file; exit;
if (file_exists($v_table_struct_xml_file) && file_exists($v_formfield_xml_file)){
	$v_table_struct_xml_string = _read_file($v_table_struct_xml_file);
	$v_formfield_xml_string = _read_file($v_formfield_xml_file);
}else{
	$v_table_struct_xml_file = "../../xml/other/cau_truc_bang_noi_dung_sau_giay_phep.xml";
	$v_formfield_xml_file = "../../xml/other/cac_dong_cua_noi_dung_sau_giay_phep.xml";
	$v_table_struct_xml_string = _read_file($v_table_struct_xml_file);
	$v_formfield_xml_string = _read_file($v_formfield_xml_file);
}

$v_table_struct_xml_string = _read_file($v_table_struct_xml_file);
$v_formfield_xml_string = _read_file($v_formfield_xml_file);
//echo htmlspecialchars($v_formfield_xml_string);
//Doc va ghi ra tieu de cua form
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_table_struct_xml_string);
$table_struct_rax->record_delim = 'common_para';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
$table_struct_row = $table_struct_rec->getRow();
$v_form_title = $table_struct_row["form_title"];
$v_first_col_width = $table_struct_row["first_col_width"];
$v_second_col_width = (100-$v_first_col_width)."%";
$v_js_file_name = $table_struct_row["js_file_name"];
$v_js_function  = $table_struct_row["js_function"];
///Begin//Form
$v_html_string = '<script src="../js-record/'.$v_js_file_name.'"></script>';
//Begin//Bang chua cac thanh phan cua form
$v_html_string = $v_html_string . "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr>";
$v_html_string = $v_html_string . "<td >&nbsp;</td>";
$v_html_string = $v_html_string . "</tr></table>";
//Bang chua cac bien hidden
$v_html_string = $v_html_string . "<table width='100%' cellpadding='0' cellspacing='0'><tr><td>";
$v_html_string = $v_html_string . "<form action='index.php' method='post' name='f_dsp_single_license'>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_list_xml_tag' value=''>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_list_xml_value' value=''>";
$v_html_string = $v_html_string . "<input type='hidden' name='fuseaction' value='DISPLAY_SINGLE_LICENSE'>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_record_id' value='".$v_record_id ."'>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_recordtype_filter' value='".$v_recordtype_filter ."'>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_isa_calendar_path' value='".$_ISA_LIB_URL_PATH."isa-calendar/'>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_work' value='".$v_detail_status ."'>";

$v_html_string = $v_html_string . "</td></tr></table>";
//Doc cac dong cua form	
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_table_struct_xml_string);
$table_struct_rax->record_delim = 'row';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 

//Bang chua cac dong cua form
$v_html_string = $v_html_string . "<table width='100%' class='form_table1'  border='0' cellspacing='0' cellpadding='0'><tr><td>";
//Begin//Bang chua cac dong co dinh cua ho so
$v_html_string = $v_html_string . "<table width='100%'  border='0' cellspacing='0' cellpadding='0'>";
$v_html_string = $v_html_string . "<col width='18%'><col width='32%'><col width='31%'><col width='19%'>";
//$v_html_string = $v_html_string . "<tr><td class='normal_label' align='center'>".CONST_REPUBLIC_LABEL."</td></tr>";
//$v_html_string = $v_html_string . "<tr><td class='normal_label' align='center'>".CONST_FREEDOM_LABEL."</td></tr>";
//$v_html_string = $v_html_string . "<tr><td class='normal_label' colspan='10' align='center'>--------------------------------------------";
$v_html_string = $v_html_string . "</td></tr>";
$v_html_string = $v_html_string . "<tr><td colspan = '2' class='large_title' style='text-align:center'>".$arr_result_label[5]."</td></tr>";
// nieuvv-010808---- them loai thu tuc va ma ho so--------------
$v_html_string = $v_html_string ."<tr class='normal_label'><td width = '9%'>".CONST_RECORD_TYPE.":</td>";
$v_html_string = $v_html_string ."<td>".$arr_single_record['C_RECORDTYPE_NAME']."</td></tr>";
$v_html_string = $v_html_string ."<tr class='normal_label'><td width = '9%'>".CONST_RECORD_CODE.":</td>";
$v_html_string = $v_html_string ."<td>".$arr_single_record['C_CODE']."</td></tr>";
//  the end --nieuvv-010808---- them loai thu tuc va ma ho so--------------
$v_html_string = $v_html_string . "</table>";

//echo htmlspecialchars($v_html_string);exit;
//End//Bang chua cac dong co dinh cua ho so
while ($table_struct_rec) { 
	$table_struct_row = $table_struct_rec->getRow();
	$v_have_line_before = $table_struct_row["have_line_before"];
	$v_col_number = $table_struct_row["col_number"];
	$v_tag_list = $table_struct_row["tag_list"];
	$v_row_id = $table_struct_row["row_id"];
	$arr_tag = explode(",", $v_tag_list);
	if ($v_have_line_before=="true"){
		$v_html_string = $v_html_string . "<table width='100%'  border='0' cellspacing='0' cellpadding='0'><tr>";
		$v_html_string = $v_html_string . "<td><hr width='100%' color='#66CCFF' size='1'></td>";
		$v_html_string = $v_html_string . "</tr></table>";
	}
	//Bang chua mot dong cua form
	$v_html_string = $v_html_string . "<table width='100%'  border='0' cellspacing='0' cellpadding='0'>";
	$v_html_table = "";
	$v_html_tag = "";		
	for($i=0;$i < sizeof($arr_tag);$i++){
		$formfield_rax = new RAX(); 
		$formfield_rec = new RAX(); 
		$formfield_rax->open($v_formfield_xml_string);
		$formfield_rax->record_delim = $arr_tag[$i];
		$formfield_rax->parse();
		$formfield_rec = $formfield_rax->readRecord(); 
		$formfield_row = $formfield_rec->getRow(); 
		$v_label = $formfield_row["label"];
		$v_type = $formfield_row["type"];
		$v_dataformat = $formfield_row["data_format"];
		$v_width = $formfield_row["width"];
		$v_row = $formfield_row["row"];
		$v_max = $formfield_row["max"];
		$v_min = $formfield_row["min"];
		$v_maxlength = $formfield_row["maxlength"];
		$v_note = $formfield_row["note"];
		$v_message = $formfield_row["message"];
		$v_optional = $formfield_row["optional"];
		$v_xml_tag_in_db = $formfield_row["xml_tag_in_db"];
		$v_js_function_list = $formfield_row["js_function_list"];
		$v_js_action_list = $formfield_row["js_action_list"];
		$v_readonly_in_edit_mode = $formfield_row["readonly_in_edit_mode"];
		$v_disabled_in_edit_mode = $formfield_row["disabled_in_edit_mode"];
		$v_value = "";		//nieuvv--171108--
		if ($v_xml_str!=""){
			$column_rax = new RAX(); 
			$column_rec = new RAX();
			$column_rax->open($v_xml_str);
			$column_rax->record_delim = 'data_list';
			$column_rax->parse();
			$column_rec = $column_rax->readRecord(); 
			$column_row = $column_rec->getRow();
			$v_value = _restore_XML_bad_char($column_row[$v_xml_tag_in_db]);			
		}
		//nieuvv--171108--lay ngay tu dong khi xu ly sau giay phep
		if($v_value == "" && $v_dataformat == "isdate")
		{
			$v_value = date("d/m/Y");
		}
		//the-end-nieuvv--171108--
		if ($v_type=="selectbox")
		{
			$v_selectbox_option_sql = $formfield_row["selectbox_option_sql"];
			$v_selectbox_id_column = $formfield_row["selectbox_option_id_column"];
			$v_selectbox_name_column = $formfield_row["selectbox_option_name_column"];
		}
		if ($v_type=="checkboxmultiple"){
			$v_checkbox_multiple_sql = $formfield_row["checkbox_multiple_sql"];
			$v_checkbox_multiple_id_column = $formfield_row["checkbox_multiple_id_column"];
			$v_checkbox_multiple_name_column = $formfield_row["checkbox_multiple_name_column"];
		}
		$v_html_table = $v_html_table . "<col width='$v_first_col_width'>" . "<col width='$v_second_col_width'>";		
		$v_html_tag = $v_html_tag . Generate_HTML_Input();		
	}
	$v_html_string = $v_html_string .  $v_html_table . "<tr id = '$v_row_id' style='display:block'>" . "<td class='normal_label'>" . $v_html_tag."</td>";
	$v_html_string = $v_html_string . "</tr></table>";
	$table_struct_rec = $table_struct_rax->readRecord();
}
$v_html_string = $v_html_string . "<tr  height='15'><td></td></tr>";
$v_html_string = $v_html_string . "</td></tr>";
//$v_html_string = $v_html_string . "<tr class='normal_label'><td><input type='checkbox' name='chk_status' value='61' $v_detail_status_check onclick='chk_onclick(this,document.forms(0).hdn_work);'>".$arr_result_label[6];
$v_html_string = $v_html_string . "</td></tr>";
$v_html_string = $v_html_string . "<tr  height='15'><td></td></tr>";
$v_html_string = $v_html_string . "</table>";
$v_html_string = $v_html_string . '<script language="JavaScript">'.$v_js_function.'</script>';
//End//Bang chua cac thanh phan cua form
//print form
echo $v_html_string;
?>
<table width='100%'  border='0' cellspacing='0' cellpadding='0'>
	<tr><td>&nbsp;</td></tr>
	<tr align="center">
		<td><?php
			if($v_is_granted_update || onegate_is_handler_for_recordtype($v_staff_id,$v_recordtype_filter,$_SESSION['recordtype'])){?>
				<input type='button' class='normal_button' name="btn_update" value='<?php echo _CONST_SAVE_BUTTON;?>' onClick="save_hidden_multiple_list(document.forms(0).chk_item_id,',');save_list_onclick(document.forms(0),document.forms(0).hdn_list_xml_tag,document.forms(0).hdn_list_xml_value);btn_save_onclick('UPDATE_POST_LICENSE');" onKeyDown="change_focus(document.forms(0),this)">&nbsp;<?php
			}?>
			<input type="button" value="<?php echo _CONST_BACK_BUTTON; ?>" name="btn_add" class="normal_button" onClick="btn_back_onclick('<?php echo $_GO_BACK?>')">
		</td>	
	</tr>
</table>
<!--//End//Form-->
</form>
<script language="JavaScript">
	set_focus(document.forms(0));
</script>